# -*- coding: utf-8 -*-

__author__ = """WebLion <support@weblion.psu.edu>"""
__docformat__ = 'plaintext'

from AccessControl import ClassSecurityInfo
from Products.Archetypes.atapi import *
from Products.ContactsDirectory.config import *
from Products.CMFCore.permissions import View
from Products.ATContentTypes.content.base import ATCTContent
from Products.ATContentTypes.content.schemata import ATContentTypeSchema, finalizeATCTSchema
from Products.ContactsDirectory.interfaces.provinces import IProvinces
from zope.interface import implements

schema = ATContentTypeSchema.copy() + Schema((

    ),

    TextField(
        name='description',
        allowable_content_types=ALLOWABLE_CONTENT_TYPES,
        widget=RichWidget(
            label=u'Description',
            label_msgid='ContactsDirectory_label_description',
            i18n_domain='ContactsDirectory',
        ),
        searchable=True,
        validators=('isTidyHtmlWithCleanup',),
        default_output_type='text/html',
        accessor="Description"
    ),

)

Provinces_schema = BaseSchema.copy() + schema.copy()  # + on Schemas does only a shallow copy
finalizeATCTSchema(Provinces_schema)

class Provinces(OrderedBaseFolder, ATCTContent):
    """
    """
    security = ClassSecurityInfo()
    __implements__ = (OrderedBaseFolder.__implements__ + ATCTContent.__implements__)
    implements(IProvinces)
    meta_type = portal_type = 'CDProvinces'

    # moved schema setting after finalizeATCTSchema, so the order of the fieldsets
    # is preserved. Also after updateActions is called since it seems to overwrite the schema changes.
    # Move the description field, but not in Plone 2.5 since it's already in the metadata tab. Although, 
    # decription and relateditems are occasionally showing up in the "default" schemata. Move them
    # to "metadata" just to be safe.
    if 'categorization' in Provinces_schema.getSchemataNames():
        Provinces_schema.changeSchemataForField('description', 'categorization')
    else:
        Provinces_schema.changeSchemataForField('description', 'metadata')
        Provinces_schema.changeSchemataForField('relatedItems', 'metadata')

    _at_rename_after_creation = True
    schema = Provinces_schema    
    # Methods

registerType(Provinces, PROJECTNAME)
# end of class Provinces

